package com.base.cn.platform.os.controller.qa.qatag;

import com.base.cn.platform.os.common.AdminBaseController;
import com.base.cn.platform.os.common.log.aop.AdminModuleEnum;
import com.base.cn.platform.os.common.log.aop.OpLog;
import com.base.cn.platform.os.service.course.qa.qatag.QaTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author LIZHIPENG
 * @since 2018/4/17
 */
@Controller
@RequestMapping("/admin/qa/qatag")
public class AdminQaTagController extends AdminBaseController {

    @Autowired
    private QaTagService qaTagService;

    /**
     * 查询标签列表
     * @param model
     * @return
     */
    @RequestMapping("/queryQaTagList")
    public String queryQaTagList(Model model){
        return resultPage("/qa/qatag/qa-tag-list");
    }

    /**
     * ajax异步查询标签列表
     * @param model
     * @param currentPage
     * @param params
     * @return
     */
    @RequestMapping("/ajaxQueryQaTagList")
    public String ajaxQueryQaTagList(Model model,
                                     @RequestParam(value = "currentPage",defaultValue = "1",required = false) int currentPage,
                                     @RequestBody Map<String,Object> params){
        params.put("status","1");
        Map<String, Object> dataMap = qaTagService.queryQaTagListPage(currentPage, params);
        model.addAttribute("dataMap", dataMap);
        return resultPage("/qa/qatag/ajax-qa-tag-list");
    }

    /**
     * 创建保存问答标签
     * @param request
     * @return
     */
    @RequestMapping("/saveQaTag")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.OTHER, action = "创建问答标签")
    public Map<String, Object> saveQaTag(HttpServletRequest request){
        Map<String, Object> qaTag = this.getParamsMap(request);
        qaTag.put("questionNum", 0);
        qaTag.put("status", 1);
        return qaTagService.saveQaTag(qaTag);
    }

    /**
     * 批量删除问答标签
     * @param tagIds 标签ID串
     * @return
     */
    @RequestMapping("/deleteQaTag")
    @ResponseBody
    @OpLog(module = AdminModuleEnum.OTHER, action = "删除问答标签")
    public Map<String, Object> deleteQaTag(@RequestParam("tagIds")String tagIds){
        return qaTagService.updateQaTag(tagIds, 3);
    }

}
